Ext.define("AmpleHarvest.util.cPropertiesDropDown", 
{
    extend			: 'Ext.form.field.ComboBox',
    alias			: 'widget.ampleharvest-util-cpropertiesdropdown',
    typeAhead		: true,
    queryMode		:'remote',
    displayField	: 'label',
    valueField		: 'terms',
    targetPath		: '',
    fixedFilter		: false,
    searchTerm		: 'propertyOptions',
    minChars		: 1,
    
	listeners		:
	{
		loadData	: function(obj_data)
		{
			this.getStore().loadRawData(obj_data);
		},
		
		reportBack	: function(str_term)
		{
//			console.log('reportback');
//			console.log(this.ownerCt);
			this.ownerCt.fireEvent(this.callbackfn, str_term);
		}
	},	
    
    initComponent:function()
    {	  
    	this.util_db_dmetedata = Ext.create('AmpleHarvest.util.solrFacets',
    			{
    				AHcaller	: this,
    				str_type	: this.valueField,
    				fixedFilter	: this.fixedFilter
    			}); 

    	Ext.define('User', {
    	    extend: 'Ext.data.Model',
    	    fields: [
    	        {name: 'count',    type: 'int'},
    	        {name: 'label',  type: 'string'},
    	        {name: 'term', type: 'string'}
    	    ]
    	});
     	
     	 
    	this.store = Ext.create('Ext.data.Store', {
    	    autoLoad: false,
    	    model: 'User',
    	    proxy: {
    	        type: 'memory',
    	        reader: {
    	            type: 'json'
    	        }
    	    }
    	});
   	
    	this.AHtypeAhead = new Ext.util.DelayedTask();
    	this.callParent();
    	
    	this.on('expand', this.get_facets, this);
    	this.on('change', this.delay_typeAhead, this);
    	this.on('select', this.set_value, this);
    },
    
    get_facets	: function()
    {
    	this.util_db_dmetedata.getData(this.searchTerm, this.getValue(), this.targetPath);
    },
    
    delay_typeAhead	: function(obj)
    {
    	obj.AHtypeAhead.delay(500, this.get_facets, this);
    },
    
    set_value	: function(obj)
    {
    	var str_term = obj.displayTplData[0].term;
//    	console.log(str_term);
    	obj.setValue(str_term);
    	this.fireEvent('reportBack', str_term);
    }
    
});